package cororpc

type TypeRetCallback = func(err error, ret any)

type (
	// IMessageArg 消息基类
	IMessageArg interface {
		GetMsgId() any
		GetMsg() any
		GetAgent() IGateAgent
		SetAgent(arent IGateAgent)
	}
	BaseMessageArg struct {
		MsgId any
		Msg   any
		Agent IGateAgent
	}
)

func (m *BaseMessageArg) GetMsgId() any {
	return m.MsgId
}
func (m *BaseMessageArg) GetMsg() any {
	return m.Msg
}
func (m *BaseMessageArg) GetAgent() IGateAgent {
	return m.Agent
}
func (m *BaseMessageArg) SetAgent(a IGateAgent) {
	m.Agent = a
}

// ReturnInfo CoroRPC的返回信息
type ReturnInfo struct {
	err error           // 返回的结果err
	ret any             // 返回的内容
	cb  TypeRetCallback // 请求回来的回调
}

// CallInfo 调用时需要的参数
type CallInfo struct {
	callFunc any // handler
	Arg      IMessageArg
	retChan  chan *ReturnInfo
	cb       TypeRetCallback // 请求回来时的回调
}

// 服务方返回给客户端
func (ci *CallInfo) ret(info *ReturnInfo) {
	if ci.retChan != nil {
		info.cb = ci.cb
		ci.retChan <- info
	}
}
